package com.xingfu.mybatisdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xingfu.mybatisdemo.dto.UserDTO;
import com.xingfu.mybatisdemo.persistence.dao.IUserDao;
import com.xingfu.mybatisdemo.persistence.mapper.SysUsersMapper;
import com.xingfu.mybatisdemo.persistence.po.SysUsers;
import com.xingfu.mybatisdemo.service.IMerchantService;
import com.xingfu.mybatisdemo.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * @author nzx
 * @version 1.0
 * @date 2019/10/28
 * @description:
 **/
@Service
@Transactional
public class MerchantService implements IMerchantService {

    @Autowired
    private IUserDao userDao;

    @Autowired
    private SysUsersMapper usersMapper;

    @Override
    public UserVO getUserAndRole(Long userId) {
        UserVO userVO = userDao.getUser(userId);
        return userVO;
    }

    @Override
    public Long insertUser(UserDTO userDTO) {
        SysUsers sysUsers = new SysUsers();
        sysUsers.setDescription(userDTO.getDescription());
        sysUsers.setPassword(userDTO.getPassword());
        sysUsers.setRealname(userDTO.getRealName());
        sysUsers.setUsername(userDTO.getUserName());
        sysUsers.setCreatedate(new Date());
        usersMapper.insert(sysUsers);
        return null;
    }

    @Override
    public PageInfo<SysUsers> getUserByPage(int curPage, int pageSize) {

//        PageHelper.startPage(curPage,pageSize);
//        List<UserVO> list = userDao.getUserByPage();
//        PageInfo<UserVO> pageInfo = new PageInfo<>(list);

        PageHelper.startPage(curPage,pageSize);
        List<SysUsers> list = userDao.getAllUser();
        PageInfo<SysUsers> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<SysUsers> getUserByDate(String time) {
//        List<SysUsers> usersList = userDao.getUserByDate(time);
        List<SysUsers> usersList = userDao.getUserforDate(new Date(1572491559000L));
        return usersList;
    }
}
